import logging
import sys
from pathlib import Path


class Logger(object):
    def __init__(self):
        self.level = logging.DEBUG
        self.logfile = Path(sys.argv[0]).parent.absolute().joinpath('fsm.log')
        self.lg = logging.getLogger('fsm')
        self.lg.setLevel(self.level)
        self.format = '[%(asctime)s][%(levelname)s][%(threadName)s:%(thread)d] - %(message)s'
        self.formatter = logging.Formatter(self.format)
        self.fh = logging.FileHandler(self.logfile, mode='a', encoding='utf-8')
        self.ch = logging.StreamHandler()
        self.fh.setFormatter(self.formatter)
        self.ch.setFormatter(self.formatter)
        self.lg.addHandler(self.fh)
        self.lg.addHandler(self.ch)

    def info(self, msg):
        self.lg.info(msg)

    def debug(self, msg):
        self.lg.debug(msg)

    def warning(self, msg):
        self.lg.warning(msg)

    def error(self, msg):
        self.lg.error(msg)


fsm_logger = Logger()
